<template>
    <div>
        <Row type="flex" justify="start" class="query-form">
            <i-col span="8">
                <Button icon="md-add" class="ivu-btn-add" @click="toEdit" v-if="!isUpdate">编辑</Button>
                <Button icon="md-add" class="ivu-btn-add" @click="saveInfo" :loading="buttonLoading" v-if="isUpdate">保存</Button>
                <Button icon="md-arrow-round-back" class="ivu-btn-add" @click="toBack" :loading="buttonLoading" v-if="isUpdate">返回</Button>
                <Button icon="md-cloud-download" class="ivu-btn-add" @click="exportExcel">导出</Button>
                <Button icon="ios-create" class="ivu-btn-add" @click="openComplete"  v-if="!isUpdate">往年补填</Button>
            </i-col>
            <i-col span="16" v-if="createUser == null">
                <div style="float:right">
                    <p style="line-height: 40px; font-family: PingFang SC; font-size: 14px">{{userInfo.companyName}}<Divider type="vertical" />当年填报年份：{{currentYear}}</p>
                </div>
            </i-col>
        </Row>
        <Row type="flex" justify="start" class="query-form" v-if="createUser != null" style="margin-top: 10px;">
            <i-col span="24">
                <div style="float:right">
                    <p style="line-height: 40px; font-family: PingFang SC; font-size: 14px">填报人：{{ createUser.userName }}<Divider type="vertical" />联系电话：{{ createUser.mobileNumber }}<Divider type="vertical" />最近更新时间：{{ createUser.updateDate == null ? formatDate(new Date(createUser.createDate), 'yyyy-MM-dd hh:mm:ss') : formatDate(new Date(createUser.updateDate), 'yyyy-MM-dd hh:mm:ss')  }}<Divider type="vertical" />{{ userInfo.companyName }}<Divider type="vertical" />当年填报年份：{{currentYear}}</p>
                </div>
            </i-col>
        </Row>
        <Table ref='table' style="margin-top: 10px" :loading="loading" border :columns="columns" no-data-text="没有查询到相关数据！"
               :data="infos" width="100%" :height="tableHeight" highlight-row stripe size="small" :show-summary="showSummary" :summary-method="handleSummary" sum-text="合计">
        </Table>
        <Modal v-model="modal1" width="800" :mask-closable="false" title="安全生产费用投入台账详情">
            <div :style="{height: divHeight, overflowY: 'auto', overflowX: 'hidden'}">
                <Form ref="formCustom" :model="formData" :rules="ruleCustom" label-position="top">
                    <Row :gutter="16">
                        <i-col span="24">
                            <FormItem label="项目：" prop="codingName">
                                <Input v-model="formData.codingName" readonly/>
                            </FormItem>
                        </i-col>
                    </Row>
                    <Row :gutter="16">
                        <i-col span="12">
                            <FormItem label="一月（万元）：" prop="codingName">
                                <Input v-model="formData.january" readonly/>
                            </FormItem>
                        </i-col>
                    </Row>
                    <Row :gutter="16">
                        <i-col span="24">
                            <FormItem label="描述：">
                                <Input v-model="formData.januaryDescription" type="textarea" readonly/>
                            </FormItem>
                        </i-col>
                    </Row>
                    <Row :gutter="16">
                        <i-col span="12">
                            <FormItem label="二月（万元）：" prop="codingName">
                                <Input v-model="formData.february" readonly/>
                            </FormItem>
                        </i-col>
                    </Row>
                    <Row :gutter="16">
                        <i-col span="24">
                            <FormItem label="描述：">
                                <Input v-model="formData.februaryDescription" type="textarea" readonly/>
                            </FormItem>
                        </i-col>
                    </Row>
                    <Row :gutter="16">
                        <i-col span="12">
                            <FormItem label="三月（万元）：" prop="codingName">
                                <Input v-model="formData.march" readonly/>
                            </FormItem>
                        </i-col>
                    </Row>
                    <Row :gutter="16">
                        <i-col span="24">
                            <FormItem label="描述：">
                                <Input v-model="formData.marchDescription" type="textarea" readonly/>
                            </FormItem>
                        </i-col>
                    </Row>
                    <Row :gutter="16">
                        <i-col span="12">
                            <FormItem label="四月（万元）：" prop="codingName">
                                <Input v-model="formData.april" readonly/>
                            </FormItem>
                        </i-col>
                    </Row>
                    <Row :gutter="16">
                        <i-col span="24">
                            <FormItem label="描述：">
                                <Input v-model="formData.aprilDescription" type="textarea" readonly/>
                            </FormItem>
                        </i-col>
                    </Row>
                    <Row :gutter="16">
                        <i-col span="12">
                            <FormItem label="五月（万元）：" prop="codingName">
                                <Input v-model="formData.may" readonly/>
                            </FormItem>
                        </i-col>
                    </Row>
                    <Row :gutter="16">
                        <i-col span="24">
                            <FormItem label="描述：">
                                <Input v-model="formData.mayDescription" type="textarea" readonly/>
                            </FormItem>
                        </i-col>
                    </Row>
                    <Row :gutter="16">
                        <i-col span="12">
                            <FormItem label="六月（万元）：" prop="codingName">
                                <Input v-model="formData.june" readonly/>
                            </FormItem>
                        </i-col>
                    </Row>
                    <Row :gutter="16">
                        <i-col span="24">
                            <FormItem label="描述：">
                                <Input v-model="formData.juneDescription" type="textarea" readonly/>
                            </FormItem>
                        </i-col>
                    </Row>
                    <Row :gutter="16">
                        <i-col span="12">
                            <FormItem label="七月（万元）：" prop="codingName">
                                <Input v-model="formData.july" readonly/>
                            </FormItem>
                        </i-col>
                    </Row>
                    <Row :gutter="16">
                        <i-col span="24">
                            <FormItem label="描述：">
                                <Input v-model="formData.julyDescription" type="textarea" readonly/>
                            </FormItem>
                        </i-col>
                    </Row>
                    <Row :gutter="16">
                        <i-col span="12">
                            <FormItem label="八月（万元）：" prop="codingName">
                                <Input v-model="formData.august" readonly/>
                            </FormItem>
                        </i-col>
                    </Row>
                    <Row :gutter="16">
                        <i-col span="24">
                            <FormItem label="描述：">
                                <Input v-model="formData.augustDescription" type="textarea" readonly/>
                            </FormItem>
                        </i-col>
                    </Row>
                    <Row :gutter="16">
                        <i-col span="12">
                            <FormItem label="九月（万元）：" prop="codingName">
                                <Input v-model="formData.september" readonly/>
                            </FormItem>
                        </i-col>
                    </Row>
                    <Row :gutter="16">
                        <i-col span="24">
                            <FormItem label="描述：">
                                <Input v-model="formData.septemberDescription" type="textarea" readonly/>
                            </FormItem>
                        </i-col>
                    </Row>
                    <Row :gutter="16">
                        <i-col span="12">
                            <FormItem label="十月（万元）：" prop="codingName">
                                <Input v-model="formData.october" readonly/>
                            </FormItem>
                        </i-col>
                    </Row>
                    <Row :gutter="16">
                        <i-col span="24">
                            <FormItem label="描述：">
                                <Input v-model="formData.octoberDescription" type="textarea" readonly/>
                            </FormItem>
                        </i-col>
                    </Row>
                    <Row :gutter="16">
                        <i-col span="12">
                            <FormItem label="十一月（万元）：" prop="codingName">
                                <Input v-model="formData.november" readonly/>
                            </FormItem>
                        </i-col>
                    </Row>
                    <Row :gutter="16">
                        <i-col span="24">
                            <FormItem label="描述：">
                                <Input v-model="formData.novemberDescription" type="textarea" readonly/>
                            </FormItem>
                        </i-col>
                    </Row>
                    <Row :gutter="16">
                        <i-col span="12">
                            <FormItem label="十二月（万元）：" prop="codingName">
                                <Input v-model="formData.december" readonly/>
                            </FormItem>
                        </i-col>
                    </Row>
                    <Row :gutter="16">
                        <i-col span="24">
                            <FormItem label="描述：">
                                <Input v-model="formData.decemberDescription" type="textarea" readonly/>
                            </FormItem>
                        </i-col>
                    </Row>
                </Form>
            </div>
            <div slot="footer">
                <Button @click="modal1 = false" class="ivu-btn-save" >关闭</Button>
            </div>
        </Modal>

        <Modal v-model="modal3" width="400" :mask-closable="false" title="安全投入补填操作">
            <Form>
                <FormItem label="补填年份：">
                    <DatePicker type="year" v-model="checkYear" format="yyyy" placeholder="请选择补填年份" style="width:100%" :options="dateOptions"></DatePicker>
                </FormItem>
            </Form>
            <div slot="footer">
                <Button @click="setCurrentYear" class="ivu-btn-save">确定</Button>
                <Button @click="modal3 = false" class="ivu-btn-cancel" >取消</Button>
            </div>
        </Modal>
    </div>
</template>

<script>
    import {sessionStorage} from '@/common/cacheUtils.js';
    import {Api} from '../../../api'
    import orgDom from "@/components/input-org.vue";

    export default {
        name: "safetyProductionList",
        components:{
            orgDom,
        },
        data(){
            return{
                createUser: null,
                checkYear: new Date(),
                currentYear: '',
                divHeight: '',
                showSummary: true,
                loading:false,
                isUpdate: false,
                columns: [
                        {
                            type: 'index',
                            title: '序号',
                            width: 80,
                            align: 'center',
                            key: 'index',
                            fixed: 'left',
                        },
                        {
                            title: '项目',
                            align: 'center',
                            key: 'codingName',
							              fixed: 'left',
                            minWidth: 230,
                            render: (h, params) => {
                                return h('div', [
                                    h('A', {
                                        props: {
                                            type: 'primary',
                                            size: 'small'
                                        },
                                        style: {
                                            fontSize: '12px'
                                        },
                                        on: {
                                            click: () => {
                                                this.formData = JSON.parse(JSON.stringify(params.row));
                                                this.modal1 = true;
                                                }
                                            }
                                        }, params.row.codingName),
                                    ]);
                                }
                            },
                            {
                                title: '1月（万元）',
                                align: 'center',
                                key: 'january',
                                minWidth: 120,
                                render:(h,params)=>{
                                    if(this.isUpdate){
                                        return h('InputNumber', {
                                            props: {
                                                value: params.row.january,
                                                min: 0
                                            },
                                            on: {
                                                'on-change': (event) => {
                                                    params.row.january = event;
                                                    this.$set(this.infos[params.index], 'january', event);
                                                }
                                            }
                                        });
                                    }else{
                                        return h('div',[
                                            h('span',params.row.january)
                                        ]);
                                    }
                                }
                            },
                            {
                                title: '描述',
                                align: 'center',
                                key: 'januaryDescription',
                                minWidth: 180,
                                render:(h,params)=>{
                                    if(this.isUpdate){
                                        return h('Input', {
                                            props: {
                                                value: params.row.januaryDescription
                                            },
                                            on: {
                                                'on-change': (event) => {
                                                    params.row.januaryDescription = event.target.value;
                                                    this.$set(this.infos[params.index], 'januaryDescription', event.target.value);
                                                }
                                            }
                                        });
                                    }else{
                                        return h('div',[
                                            h('span',params.row.januaryDescription)
                                        ]);
                                    }
                                }
                            },
                            {
                                title: '2月（万元）',
                                align: 'center',
                                key: 'february',
                                minWidth: 120,
                                render:(h,params)=>{
                                    if(this.isUpdate){
                                        return h('InputNumber', {
                                            props: {
                                                value: params.row.february != undefined? params.row.february : '',
                                                min: 0
                                            },
                                            on: {
                                                'on-change': (event) => {
                                                    params.row.february = event;
                                                    this.$set(this.infos[params.index], 'february', event);
                                                }
                                            }
                                        });
                                    }else{
                                        return h('div',[
                                            h('span',params.row.february)
                                        ]);
                                    }
                                }
                            },
                            {
                                title: '描述',
                                align: 'center',
                                key: 'februaryDescription',
                                minWidth: 180,
                                render:(h,params)=>{
                                    if(this.isUpdate){
                                        return h('Input', {
                                            props: {
                                                value: params.row.februaryDescription
                                            },
                                            on: {
                                                'on-change': (event) => {
                                                    params.row.februaryDescription = event.target.value;
                                                    this.$set(this.infos[params.index], 'februaryDescription', event.target.value);
                                                }
                                            }
                                        });
                                    }else{
                                        return h('div',[
                                            h('span',params.row.februaryDescription)
                                        ]);
                                    }
                                }
                            },
                            {
                                title: '3月（万元）',
                                align: 'center',
                                key: 'march',
                                minWidth: 120,
                                render:(h,params)=>{
                                    if(this.isUpdate){
                                        return h('InputNumber', {
                                            props: {
                                                value: params.row.march != undefined? params.row.march : '',
                                                min: 0
                                            },
                                            on: {
                                                'on-change': (event) => {
                                                    params.row.march = event;
                                                    this.$set(this.infos[params.index], 'march', event);
                                                }
                                            }
                                        });
                                    }else{
                                        return h('div',[
                                            h('span',params.row.march)
                                        ]);
                                    }
                                }
                            },
                            {
                                title: '描述',
                                align: 'center',
                                key: 'marchDescription',
                                minWidth: 180,
                                render:(h,params)=>{
                                    if(this.isUpdate){
                                        return h('Input', {
                                            props: {
                                                value: params.row.marchDescription
                                            },
                                            on: {
                                                'on-change': (event) => {
                                                    params.row.marchDescription = event.target.value;
                                                    this.$set(this.infos[params.index], 'marchDescription', event.target.value);
                                                }
                                            }
                                        });
                                    }else{
                                        return h('div',[
                                            h('span',params.row.marchDescription)
                                        ]);
                                    }
                                }
                            },
                            {
                                title: '4月（万元）',
                                align: 'center',
                                key: 'april',
                                minWidth: 120,
                                render:(h,params)=>{
                                    if(this.isUpdate){
                                        return h('InputNumber', {
                                            props: {
                                                value: params.row.april != undefined? params.row.april : '',
                                                min: 0
                                            },
                                            on: {
                                                'on-change': (event) => {
                                                    params.row.april = event;
                                                    this.$set(this.infos[params.index], 'april', event);
                                                }
                                            }
                                        });
                                    }else{
                                        return h('div',[
                                            h('span',params.row.april)
                                        ]);
                                    }
                                }
                            },
                            {
                                title: '描述',
                                align: 'center',
                                key: 'aprilDescription',
                                minWidth: 180,
                                render:(h,params)=>{
                                    if(this.isUpdate){
                                        return h('Input', {
                                            props: {
                                                value: params.row.aprilDescription
                                            },
                                            on: {
                                                'on-change': (event) => {
                                                    params.row.aprilDescription = event.target.value;
                                                    this.$set(this.infos[params.index], 'aprilDescription', event.target.value);
                                                }
                                            }
                                        });
                                    }else{
                                        return h('div',[
                                            h('span',params.row.aprilDescription)
                                        ]);
                                    }
                                }
                            },
                            {
                                title: '5月（万元）',
                                align: 'center',
                                key: 'may',
                                minWidth: 120,
                                render:(h,params)=>{
                                    if(this.isUpdate){
                                        return h('InputNumber', {
                                            props: {
                                                value: params.row.may != undefined? params.row.may : '',
                                                min: 0
                                            },
                                            on: {
                                                'on-change': (event) => {
                                                    params.row.may = event;
                                                    this.$set(this.infos[params.index], 'may', event);
                                                }
                                            }
                                        });
                                    }else{
                                        return h('div',[
                                            h('span',params.row.may)
                                        ]);
                                    }
                                }
                            },
                            {
                                title: '描述',
                                align: 'center',
                                key: 'mayDescription',
                                minWidth: 180,
                                render:(h,params)=>{
                                    if(this.isUpdate){
                                        return h('Input', {
                                            props: {
                                                value: params.row.mayDescription
                                            },
                                            on: {
                                                'on-change': (event) => {
                                                    params.row.mayDescription = event.target.value;
                                                    this.$set(this.infos[params.index], 'mayDescription', event.target.value);
                                                }
                                            }
                                        });
                                    }else{
                                        return h('div',[
                                            h('span',params.row.mayDescription)
                                        ]);
                                    }
                                }
                            },
                            {
                                title: '6月（万元）',
                                align: 'center',
                                key: 'june',
                                minWidth: 120,
                                render:(h,params)=>{
                                    if(this.isUpdate){
                                        return h('InputNumber', {
                                            props: {
                                                value: params.row.june != undefined? params.row.june : '',
                                                min: 0
                                            },
                                            on: {
                                                'on-change': (event) => {
                                                    params.row.june = event;
                                                    this.$set(this.infos[params.index], 'june', event);
                                                }
                                            }
                                        });
                                    }else{
                                        return h('div',[
                                            h('span',params.row.june)
                                        ]);
                                    }
                                }
                            },
                            {
                                title: '描述',
                                align: 'center',
                                key: 'juneDescription',
                                minWidth: 180,
                                render:(h,params)=>{
                                    if(this.isUpdate){
                                        return h('Input', {
                                            props: {
                                                value: params.row.juneDescription
                                            },
                                            on: {
                                                'on-change': (event) => {
                                                    params.row.juneDescription = event.target.value;
                                                    this.$set(this.infos[params.index], 'juneDescription', event.target.value);
                                                }
                                            }
                                        });
                                    }else{
                                        return h('div',[
                                            h('span',params.row.juneDescription)
                                        ]);
                                    }
                                }
                            },
                            {
                                title: '7月（万元）',
                                align: 'center',
                                key: 'july',
                                minWidth: 120,
                                render:(h,params)=>{
                                    if(this.isUpdate){
                                        return h('InputNumber', {
                                            props: {
                                                value: params.row.july != undefined? params.row.july : '',
                                                min: 0
                                            },
                                            on: {
                                                'on-change': (event) => {
                                                    params.row.july = event;
                                                    this.$set(this.infos[params.index], 'july', event);
                                                }
                                            }
                                        });
                                    }else{
                                        return h('div',[
                                            h('span',params.row.july)
                                        ]);
                                    }
                                }
                            },
                            {
                                title: '描述',
                                align: 'center',
                                key: 'julyDescription',
                                minWidth: 180,
                                render:(h,params)=>{
                                    if(this.isUpdate){
                                        return h('Input', {
                                            props: {
                                                value: params.row.julyDescription
                                            },
                                            on: {
                                                'on-change': (event) => {
                                                    params.row.julyDescription = event.target.value;
                                                    this.$set(this.infos[params.index], 'julyDescription', event.target.value);
                                                }
                                            }
                                        });
                                    }else{
                                        return h('div',[
                                            h('span',params.row.julyDescription)
                                        ]);
                                    }
                                }
                            },
                            {
                                title: '8月（万元）',
                                align: 'center',
                                key: 'august',
                                minWidth: 120,
                                render:(h,params)=>{
                                    if(this.isUpdate){
                                        return h('InputNumber', {
                                            props: {
                                                value: params.row.august != undefined? params.row.august : '',
                                                min: 0
                                            },
                                            on: {
                                                'on-change': (event) => {
                                                    params.row.august = event;
                                                    this.$set(this.infos[params.index], 'august', event);
                                                }
                                            }
                                        });
                                    }else{
                                        return h('div',[
                                            h('span',params.row.august)
                                        ]);
                                    }
                                }
                            },
                            {
                                title: '描述',
                                align: 'center',
                                key: 'augustDescription',
                                minWidth: 180,
                                render:(h,params)=>{
                                    if(this.isUpdate){
                                        return h('Input', {
                                            props: {
                                                value: params.row.augustDescription
                                            },
                                            on: {
                                                'on-change': (event) => {
                                                    params.row.augustDescription = event.target.value;
                                                    this.$set(this.infos[params.index], 'augustDescription', event.target.value);
                                                }
                                            }
                                        });
                                    }else{
                                        return h('div',[
                                            h('span',params.row.augustDescription)
                                        ]);
                                    }
                                }
                            },
                            {
                                title: '9月（万元）',
                                align: 'center',
                                key: 'september',
                                minWidth: 120,
                                render:(h,params)=>{
                                    if(this.isUpdate){
                                        return h('InputNumber', {
                                            props: {
                                                value: params.row.september != undefined? params.row.september : '',
                                                min: 0
                                            },
                                            on: {
                                                'on-change': (event) => {
                                                    params.row.september = event;
                                                    this.$set(this.infos[params.index], 'september', event);
                                                }
                                            }
                                        });
                                    }else{
                                        return h('div',[
                                            h('span',params.row.september)
                                        ]);
                                    }
                                }
                            },
                            {
                                title: '描述',
                                align: 'center',
                                key: 'septemberDescription',
                                minWidth: 180,
                                render:(h,params)=>{
                                    if(this.isUpdate){
                                        return h('Input', {
                                            props: {
                                                value: params.row.septemberDescription
                                            },
                                            on: {
                                                'on-change': (event) => {
                                                    params.row.septemberDescription = event.target.value;
                                                    this.$set(this.infos[params.index], 'septemberDescription', event.target.value);
                                                }
                                            }
                                        });
                                    }else{
                                        return h('div',[
                                            h('span',params.row.septemberDescription)
                                        ]);
                                    }
                                }
                            },
                            {
                                title: '10月（万元）',
                                align: 'center',
                                key: 'october',
                                minWidth: 120,
                                render:(h,params)=>{
                                    if(this.isUpdate){
                                        return h('InputNumber', {
                                            props: {
                                                value: params.row.october != undefined? params.row.october : '',
                                                min: 0
                                            },
                                            on: {
                                                'on-change': (event) => {
                                                    params.row.october = event;
                                                    this.$set(this.infos[params.index], 'october', event);
                                                }
                                            }
                                        });
                                    }else{
                                        return h('div',[
                                            h('span',params.row.october)
                                        ]);
                                    }
                                }
                            },
                            {
                                title: '描述',
                                align: 'center',
                                key: 'octoberDescription',
                                minWidth: 180,
                                render:(h,params)=>{
                                    if(this.isUpdate){
                                        return h('Input', {
                                            props: {
                                                value: params.row.octoberDescription
                                            },
                                            on: {
                                                'on-change': (event) => {
                                                    params.row.octoberDescription = event.target.value;
                                                    this.$set(this.infos[params.index], 'octoberDescription', event.target.value);
                                                }
                                            }
                                        });
                                    }else{
                                        return h('div',[
                                            h('span',params.row.octoberDescription)
                                        ]);
                                    }
                                }
                            },
                            {
                                title: '11月（万元）',
                                align: 'center',
                                key: 'november',
                                minWidth: 120,
                                render:(h,params)=>{
                                    if(this.isUpdate){
                                        return h('InputNumber', {
                                            props: {
                                                value: params.row.november != undefined? params.row.november : '',
                                                min: 0
                                            },
                                            on: {
                                                'on-change': (event) => {
                                                    params.row.november = event;
                                                    this.$set(this.infos[params.index], 'november', event);
                                                }
                                            }
                                        });
                                    }else{
                                        return h('div',[
                                            h('span',params.row.november)
                                        ]);
                                    }
                                }
                            },
                            {
                                title: '描述',
                                align: 'center',
                                key: 'novemberDescription',
                                minWidth: 180,
                                render:(h,params)=>{
                                    if(this.isUpdate){
                                        return h('Input', {
                                            props: {
                                                value: params.row.novemberDescription
                                            },
                                            on: {
                                                'on-change': (event) => {
                                                    params.row.novemberDescription = event.target.value;
                                                    this.$set(this.infos[params.index], 'novemberDescription', event.target.value);
                                                }
                                            }
                                        });
                                    }else{
                                        return h('div',[
                                            h('span',params.row.novemberDescription)
                                        ]);
                                    }
                                }
                            },
                            {
                                title: '12月（万元）',
                                align: 'center',
                                key: 'december',
                                minWidth: 120,
                                render:(h,params)=>{
                                    if(this.isUpdate){
                                        return h('InputNumber', {
                                            props: {
                                                value: params.row.december != undefined? params.row.december : '',
                                                min: 0
                                            },
                                            on: {
                                                'on-change': (event) => {
                                                    params.row.december = event;
                                                    this.$set(this.infos[params.index], 'december', event);
                                                }
                                            }
                                        });
                                    }else{
                                        return h('div',[
                                            h('span',params.row.december)
                                        ]);
                                    }
                                }
                            },
                            {
                                title: '描述',
                                align: 'center',
                                key: 'costDescription',
                                minWidth: 200,
                                render:(h,params)=>{
                                    if(this.isUpdate){
                                        return h('Input', {
                                            props: {
                                                value: params.row.decemberDescription != undefined? params.row.decemberDescription : ''
                                            },
                                            on: {
                                                'on-change': (event) => {
                                                    params.row.decemberDescription = event.target.value;
                                                    this.$set(this.infos[params.index], 'decemberDescription', event.target.value);
                                                }
                                            }
                                        });
                                    }else{
                                        return h('div',[
                                            h('span',params.row.decemberDescription)
                                        ]);
                                    }
                                }
                            },
                            {
                                title: '合计',
                                width: 80,
                                align: 'center',
                                fixed: 'right',
                                key: 'total',
                                render:(h,params)=>{
                                    let newpar = parseFloat(params.row.total);
                                    return h('div',[
                                        h('span',newpar)
                                    ]);
                                }
                            },
                    // {
                    //     title: '操作',
                    //     width: 80,
                    //     align: 'center',
                    //     fixed: 'right',
                    //     render: (h, params) => {
                    //         return h('div', [
                    //             h('A', {
                    //                 props: {
                    //                     type: 'primary',
                    //                     size: 'small'
                    //                 },
                    //                 style: {
                    //                     fontSize: '14px'
                    //                 },
                    //                 on: {
                    //                     click: () => {
                    //                         this.formData = JSON.parse(JSON.stringify(params.row));
                    //                         this.$set(this.formData, 'orgId', this.userInfo.companyId);
                    //                         this.modal1= true;
                    //                     }
                    //                 }
                    //             }, '编辑'),
                    //         ]);
                    //     }
                    // }
                ],
                tableHeight: '',
                infos: [],
                userInfo: sessionStorage('userId').getObject('userId'),
                modal1: false,
                modal2: false,
                modal3: false,
                formData: {},
                ruleCustom: {},
                buttonLoading: false,
                companyInfo: {},
                dateOptions: {
                    disabledDate (date) {
                        return date && date.valueOf() > Date.now() - 86400000;
                    }
                }
            }
        },
        mounted(){
            this.currentYear = new Date().getFullYear();
            this.tableHeight = window.innerHeight - this.$refs.table.$el.offsetTop - 145;
            this.divHeight = window.innerHeight - 150 +'px';
            this.$set(this.companyInfo, 'companyId', this.userInfo.companyId);
            this.$set(this.companyInfo, 'companyName', this.userInfo.companyName);
            this.query();
        },
        methods: {
            query(){
                // let date = new Date();
                let data = {
                    orgId: this.userInfo.companyId,
                    year: this.currentYear,
					orgName: this.userInfo.companyName,
                };
                this.loading = true;
                this.$http.get(Api.safetyProduction, {
                    params: data
                }).then(function(res){
                    if(res.data.status === 200){
                        if(res.data.data.user == null){
                            res.data.data.data.map((i)=>{
                                i.orgId = this.userInfo.companyId;
                            })
                        }else{
                            this.createUser = res.data.data.user;
                        }
                        this.infos = res.data.data.data;
                        this.loading = false;
                    }else{
                        this.$Message.error('请求失败');
                    }                    
                }, function(res){
                    this.$Message.error('请求失败');
                });
            },
            toEdit(){
                // if(this.createUser != null){
                //     if(this.createUser.userId != this.userInfo.userId && this.userInfo.userBeHandedOver.find(obj => obj == this.createUser.userId) === undefined){
                //         this.$Message.error('当前数据只允许填报人进行操作！');
                //         return;
                //     }
                // }
                this.modal2 = true;
                this.isUpdate = true;
                this.showSummary = false;
                this.addColumns();
            },
            toBack(){
                this.isUpdate = false;
                this.showSummary = true;
                this.query();
                this.addColumns();
            },
            addColumns(){
                // if(!this.isUpdate){
                //     // this.columns.splice(this.columns.length-1, 1);
                //     this.columns.push(
                //         {
                //             title: '合计',
                //             width: 80,
                //             align: 'center',
                //             fixed: 'right',
                //         }
                //     );
                // }
                // else{
                //     this.columns.push(
                //         {
                //             title: '操作',
                //             width: 80,
                //             align: 'center',
                //             fixed: 'right',
                //             render: (h, params) => {
                //                 return h('div', [
                //                     h('Button', {
                //                         props: {
                //                             type: 'success'
                //                         },
                //                         on: {
                //                             click: () => {
                //                                 this.saveInfo(params.row);
                //                             }
                //                         }
                //                     }, '保存')
                //                 ]);
                //             }
                //         }
                //     );
                // }
            },
            saveInfo(){
                this.buttonLoading = true;
                this.infos.map((i=>{
                    i.year = this.currentYear;
                }))
                this.$http.post(Api.safetyProduction + '/list',this.infos).then(function(response){
                    this.buttonLoading = false;
                    this.toBack();
                    this.query();
                    this.$Message.success({  content: '保存成功', duration: 4 });
                });

                // if(this.formData.id == undefined){
                //     this.$http.post(Api.safetyProduction,this.formData).then(function(response){
                //         this.buttonLoading = false;
                //         this.modal1 = false;
                //         this.query();
                //         this.$Message.success({  content: '保存成功', duration: 4 });
                //     });
                // }else{
                //     this.$http.put(Api.safetyProduction,this.formData).then(function(response){
                //         this.buttonLoading = false;
                //         this.modal1 = false;
                //         this.query();
                //         this.$Message.success({  content: '保存成功', duration: 4 });
                //     });
                // }
            },
            exportExcel(){
                let date = new Date();
                let data = {
                    orgId: this.userInfo.companyId,
                    year: date.getFullYear(),
					orgName: this.userInfo.companyName,
                };
                this.$http.get(Api.safetyProduction + '/excel',{
                    params: data,
                    responseType: 'arraybuffer'
                }).then((res) => {
                    const aLink = document.createElement("a");
                    let blob = new Blob([res.data], {
                        type: "application/vnd.ms-excel"
                    })
                    aLink.href = URL.createObjectURL(blob);
                    aLink.download = "安全生产费用投入台账.xlsx" //标题
                    aLink.click();
                    document.body.appendChild(aLink);
                }, function(res){
                    this.$Message.error('生成失败');
                })
            },
            handleSummary({ columns, data }){
                const sums = {};
                columns.forEach((column, index) => {
                    const key = column.key;
                    if (index === 2) {
                        sums[key] = {
                            key,
                            value: '合计'
                        };
                        return;
                    }
                    if(column.title != '描述'){
                        const values = data.map(item => Number(item[key]));
                        if (!values.every(value => isNaN(value))) {
                            const v = values.reduce((prev, curr) => {
                                const value = Number(curr);
                                if (!isNaN(value)) {
                                    return prev + curr;
                                } else {
                                    return prev;
                                }
                            }, 0);
                            sums[key] = {
                                key,
                                value: v.toFixed(6)
                            };
                        } else {
                            sums[key] = {
                                key,
                                value: ''
                            };
                        }
                    }else{
                        sums[key] = {
                            key,
                            value: ''
                        };
                    }

                });
                return sums;
            },
            openComplete(){
                this.modal3 = true;
            },
            setCurrentYear(){
                if(this.checkYear == ''){
                    this.$Message.error('请选择补填日期');
                    return;
                }
                this.currentYear = this.checkYear.getFullYear();
                this.query();
                this.modal3 = false;
            },
            formatDate(date, fmt) {
                if (/(y+)/.test(fmt)) {
                    fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
                }
                let o = {
                    'M+': date.getMonth() + 1,
                    'd+': date.getDate(),
                    'h+': date.getHours(),
                    'm+': date.getMinutes(),
                    's+': date.getSeconds()
                };
                for (let k in o) {
                    if (new RegExp(`(${k})`).test(fmt)) {
                    let str = o[k] + '';
                    fmt = fmt.replace(RegExp.$1, RegExp.$1.length === 1 ? str : this.padLeftZero(str));
                    }
                }
                return fmt;
            },
            padLeftZero(str) {
                return ('00' + str).substr(str.length);
            },
        }
    }
</script>
<style scoped>

</style>
